package com.zuxia.controller;


import com.zuxia.entity.Group;
import com.zuxia.param.GroupParam;
import com.zuxia.service.GroupService;
import com.zuxia.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author laoli
 * @since 2024-11-15
 */
@RestController
@RequestMapping("/group")
@Api("拼团接口")
public class GroupController {
    @Resource
    private GroupService groupService;

    @ApiOperation("审核通过")
    @GetMapping("/admin/token/reviewer/true/{id}")
    public R upGroupStatusIsTrue(@PathVariable("id") String id) throws Exception{
        return R.ok().message("审核状态修改成功").data("group-reviewer-true", groupService.upGroupStatus(id,2));
    }

    @ApiOperation("审核不通过")
    @GetMapping("/admin/token/reviewer/false/{id}")
    public R upGroupStatusIsFalse(@PathVariable("id") String id) throws Exception{
        return R.ok().message("审核状态修改成功").data("group-reviewer-false", groupService.upGroupStatus(id,2));
    }
    @RestController
    @RequestMapping("/group/merchant")
    class Merchant{

        @ApiOperation("发货")
        @GetMapping("/send/shop/{id}")
        public R sendShop(@PathVariable("id") String group) throws Exception{
            return R.ok().message("发货成功").data("group-send-shop", groupService.sendShop(group));
        }

        @ApiOperation("修改拼团成功次数")
        @GetMapping("/token/up/{id}/{num}")
        public R upGroupSuccessNum(@PathVariable("id") String id,@PathVariable("num") Integer num) throws Exception{
            return R.ok().message("修改成功").data("group-up", groupService.upGroupSuccessNum(id,num));
        }

        @ApiOperation("新建拼团设置")
        @PostMapping("/add")
        public R addGroup(@RequestBody Group group) throws Exception{
            return R.ok().message("创建拼团设置成功").data("group", groupService.addGroup(group));
        }

        @ApiOperation("拼团配置信息")
        @GetMapping("/single/{id}")
        public R getGroupById(@PathVariable("id") String id) throws Exception{
            return R.ok().message("拼团信息").data("group-single", groupService.getGroupById(id));
        }

        @ApiOperation("发布拼团(上架商品)")
        @GetMapping("/release/{id}")
        public R releaseGroup(@PathVariable("id") String id) throws Exception{
            return R.ok().message("拼团发布").data("group-shop-release", groupService.releaseGroup(id,1));
        }

        @ApiOperation("停止拼团(下架商品)")
        @GetMapping("/stop/{id}")
        public R releaseStopGroup(@PathVariable("id") String id) throws Exception{
            return R.ok().message("停止拼团").data("group-shop-stop", groupService.releaseGroup(id,0));
        }

        @ApiOperation("拼团分页查询")
        @PostMapping("/page")
        public R getGroupByPage(@RequestBody GroupParam groupParam) throws Exception{
            return R.ok().message("查询结果").data("group-all", groupService.getGroupByPage(groupParam));
        }
    }
}

